/**
 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// Generate macro for each intrinsic - bridge name, function name, parameters count:
//   ENTRYPOINT PowF64Bridge, PowF64, 2

% Compiler::intrinsics.select(&:has_impl?).uniq { |intrn| intrn.impl + ", " + intrn.impl_signature.args.count.to_s + ";;" + intrn.private.to_s}
% .each do |intrn|
%     if intrn.private
#ifndef PANDA_PRODUCT_BUILD
%     end
% implementation = intrn.impl.rpartition("::").last
// Default intrinsic implementation with runtime_call which is called by Codegen::CallIntrinsic
ENTRYPOINT <%= implementation %>Bridge, <%= implementation %>, <%= intrn.impl_signature.args.count.to_s %>, <%= ((intrn.impl_signature.ret == "void") ? 1 : 0) %>
// Default implementation for virtually called intrinsics from compiled frame
ENTRYPOINT <%= implementation %>CompiledAbiBridge, <%= implementation %>CompiledAbi, <%= (intrn.impl_signature.args.count + 1).to_s %>, <%= ((intrn.impl_signature.ret == "void") ? 1 : 0) %>
// Depending on frame kind choose either CompiledAbiBridge (for compiled frame) or CompiledAbi (for interpreted frame) for virtual intrinsic
BRIDGE_SELECTOR <%= implementation %>BridgeSelectorEntryPoint, <%= implementation %>CompiledAbi, <%= implementation %>CompiledAbiBridge
#ifndef NDEBUG
%   implementation = intrn.fast_path if intrn.respond_to?(:fast_path)
%   if intrn.respond_to?(:fast_path)
#if defined(PANDA_TARGET_AMD64) && !defined(PANDA_COMPILER_TARGET_X86_64)
RUNTIME_CALL_CHECKER <%= intrn.impl.rpartition("::").last %>RuntimeCallChecker, <%= intrn.impl.rpartition("::").last %>
#else
%   end
RUNTIME_CALL_CHECKER <%= implementation %>RuntimeCallChecker, <%= implementation %>
%   if intrn.respond_to?(:fast_path)
#endif
%   end
#endif

%     if intrn.private
#endif  // PANDA_PRODUCT_BUILD
%     end
% end
